package org.example.controller;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.example.BlogServiceApi;
import org.example.UserServiceApi;
import org.example.pojo.*;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserController implements UserServiceApi {

    @Autowired
    private UserService userService;


    @Override
    public Result<UserLoginResponse> login(@Validated @RequestBody UserInfoRequest user) {
        return  Result.success(userService.login(user));
    }

    @Override
    public Result<UserInfoResponse> getUserInfo(@NotNull Integer userId) {
       return Result.success(userService.getUserInfo(userId));
    }

    /**
     * 根据博客的id来获取作者的信息
     * @param blogId
     * @return
     */
    @Override
    public Result<UserInfoResponse> getAuthorInfo(@NotNull Integer blogId) {
       return Result.success(userService.selectAuthorInfoByBlogId(blogId));
    }

    @Override
    public Result<Integer> register(@Validated @RequestBody UserInfoRegisterRequest registerRequest) {
        return Result.success(userService.registerUser(registerRequest));
    }
}
